using Assets.Scripts.GDK;
using SimpleJson;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using UnityEngine;

namespace Brick
{
	public class GameManager : gdk_game_manager
	{
		public static bool isLiuHaiShape = true;

		public static LevelModel getIndexGameDataLevelModel(int index)
		{
			List<LevelListModel> levelListCellList = GameData.gameData.levelListCellList;
			for (int i = 0; i < levelListCellList.Count; i++)
			{
				if (index < levelListCellList[i].startIndex || index >= levelListCellList[i].endIndex)
				{
					continue;
				}
				LevelItemModel[] array = levelListCellList[i].levelModelList.ToArray();
				for (int j = 0; j < array.Length; j++)
				{
					if (index == array[j].index)
					{
						gdk_game_manager.log(">on getIndexGameDataLevelModel" + array[j].levelModel);
						return array[j].levelModel;
					}
				}
			}
			return null;
		}

		public static List<string> getCurAnswerList()
		{
			int index = GameData.index;
			return getIndexAnswerList(index);
		}

		public static List<string> getIndexAnswerList(int index)
		{
			LevelModel indexGameDataLevelModel = getIndexGameDataLevelModel(index);
			if (indexGameDataLevelModel == null)
			{
				return new List<string>();
			}
			List<string> list = new List<string>();
			string[] cellList = indexGameDataLevelModel.cellList;
			for (int i = 0; i < indexGameDataLevelModel.cellList.Length; i++)
			{
				string[] array = Regex.Split(cellList[i], ",", RegexOptions.IgnoreCase);
				list.Add(array[array.Length - 1]);
			}
			return list;
		}

		public static void setGameShopModelArray(GameShopModel[] gameShopModelArray)
		{
			GameData.gameShopArray = gameShopModelArray;
		}

		public static void setGameGiftModelArray(GameGiftModel[] gameShopModelArray)
		{
			GameData.gameGiftArray = gameShopModelArray;
		}

		public static void setPifuModelArray(PiFuModel[] pifuModelArray)
		{
			GameData.piFuArray = pifuModelArray;
		}

		public static void setDaysModelArray(DayModel[] sixModelArray, DayModel[] sevenModelArray)
		{
			GameData.DaysArray = sixModelArray;
			GameData.Days7Array = sevenModelArray;
		}

		public static void setGameConfig(GameConfigModel gameConfigModel)
		{
			GameData.gameConfig = gameConfigModel;
		}

		public static void setGameData(GameDataModel gameDataModel)
		{
			GameData.gameData = gameDataModel;
		}

		public static void setAnswerList(List<string> answerList)
		{
			GameData.answerList = answerList;
		}

		public static void addCoin(int val)
		{
			GameData.coin += val;
			gdk_game_manager.DispachEvent(EventID.UPDATA_COIN, GameData.coin);
		}

		public static void addRecord(float val)
		{
			GameData.record += val;
		}

		public static void addStar(int val)
		{
			GameData.stars += val;
			gdk_game_manager.DispachEvent(EventID.UPDATA_STAR, GameData.stars);
		}

		public static void changeLight()
		{
			if (GameData.curLight == 0)
			{
				GameData.curLight = 1;
			}
			else
			{
				GameData.curLight = 0;
			}
		}

		public static void OnSignDay(int day)
		{
			List<int> list = new List<int>();
			if (!(GameData.dailyRecod == string.Empty))
			{
				list = SimpleJson.SimpleJson.DeserializeObject<List<int>>(GameData.dailyRecod);
			}
			list.Add(DateTime.Today.DayOfYear);
			GameData.dailyRecod = SimpleJson.SimpleJson.SerializeObject(list);
		}

		public static List<int> GetSignDays()
		{
			if (GameData.dailyRecod == string.Empty)
			{
				return null;
			}
			return SimpleJson.SimpleJson.DeserializeObject<List<int>>(GameData.dailyRecod);
		}

		public static void OnResetSignDays()
		{
			GameData.dailyRecod = string.Empty;
		}

		public static bool getSelectIndexIsIndex()
		{
			int selectIndex = GameData.selectIndex;
			int index = GameData.index;
			return selectIndex == index;
		}

		public static float getIndexTime()
		{
			int index = GameData.index;
			int playLevelIndex = GameData.playLevelIndex;
			if (playLevelIndex != index)
			{
				return 0f;
			}
			return GameData.playLevelTime;
		}

		public static void addIndexTime(float time)
		{
			if (getSelectIndexIsIndex())
			{
				int index = GameData.index;
				int playLevelIndex = GameData.playLevelIndex;
				if (playLevelIndex < index)
				{
					GameData.playLevelTime = 0f;
					GameData.playLevelIndex = index;
				}
				else
				{
					float indexTime = getIndexTime();
					indexTime = (GameData.playLevelTime = indexTime + time);
				}
			}
		}

		public static int getEverydayEndLevelLength()
		{
			TimeModel lastTime = gdk_game_manager.getLastTime();
			if (gdk_utils.getTimeModelIsCurDay(lastTime))
			{
				return GameData.curDayEndLevelLen;
			}
			return 0;
		}

		public static void addEverydayEndLevelLength()
		{
			TimeModel lastTime = gdk_game_manager.getLastTime();
			if (gdk_utils.getTimeModelIsCurDay(lastTime))
			{
				GameData.curDayEndLevelLen++;
			}
			else
			{
				GameData.curDayEndLevelLen = 1;
			}
		}

		public static void getWordInfoItem(string key, Action<WordInfoItemModel> callback)
		{
			WordInfoModel wordInfoJson = getWordInfoJson();
			for (int i = 0; i < wordInfoJson.data.Count; i++)
			{
				WordInfoItemModel wordInfoItemModel = wordInfoJson.data[i];
				if (wordInfoItemModel != null && key == wordInfoItemModel.key)
				{
					callback(wordInfoItemModel);
				}
			}
		}

		private static WordInfoModel getWordInfoJson()
		{
			WordInfoModel wordInfoModel = GameData.wordInfo;
			if (wordInfoModel == null)
			{
				wordInfoModel = (GameData.wordInfo = GDK.ModuleManger.Module<LogoSceneModule>().loadWordInfoJson());
			}
			return wordInfoModel;
		}

		public static GameShopModel getGameShopModel(int shopID)
		{
			GameShopModel[] gameShopArray = GameData.gameShopArray;
			foreach (GameShopModel gameShopModel in gameShopArray)
			{
				if (gameShopModel.shopID == shopID)
				{
					return gameShopModel;
				}
			}
			return null;
		}

		public static float getIndexAdSwitchOdds(int index)
		{
			int num = index + 1;
			/*List<AdSwitchModel> adSwitchList = SDKManager.AdSwitchList;
			for (int i = 0; i < adSwitchList.Count; i++)
			{
				AdSwitchModel adSwitchModel = adSwitchList[i];
				if (num >= adSwitchModel.start && num <= adSwitchModel.end)
				{
					return adSwitchModel.odds;
				}
			}*/
			return 0f;
		}

		public static void showAddCoinAlert(int coin, int ID)
		{
			gdk_game_manager.showAlert(AlertID.REWARD_COIN_ALERT, delegate (GameObject obj)
			{
				RewardCoinAlert component = obj.GetComponent<RewardCoinAlert>();
				component.OnData(coin.ToString(), ID);
			});
		}

		public static void showRewardsAlert(DayModel[] dayInfo)
		{
			gdk_game_manager.showAlert(AlertID.REWARD_S_ALERT, delegate (GameObject obj)
			{
				RewardsAlert component = obj.GetComponent<RewardsAlert>();
				component.OnData(dayInfo);
			});
		}

		public static void PlayAdvert(string adunitId, string sendAdType, Action callback)
		{
			PlayAdvert(adunitId, sendAdType, callback, callback, callback, string.Empty);
		}

		public static void PlayAdvert(string adunitId, string sendAdType, Action callback, Action errCallback)
		{
			PlayAdvert(adunitId, sendAdType, callback, errCallback, errCallback, string.Empty);
		}

		public static void PlayAdvert(string adunitId, string sendAdType, Action callback, Action errCallback, Action cancelCallback, string extrainfo = "")
		{
			gdk_game_manager.log("准备播放视频", 10f);
			bool isOvertime = false;
			IEnumerator ie = null;
			ie = gdk_runTime.setTimeOut(delegate
			{
				isOvertime = true;
				gdk_game_manager.log("Debug,等待超时...", 10f);
				errCallback();
			}, 6f);
			/*SDKManager.ClickAdvert(adunitId, sendAdType, delegate(int code)
			{
				gdk_game_manager.log("视频结果:" + code, 10f);
				if (ie != null)
				{
					gdk_runTime.clear(ie);
				}
				if (isOvertime)
				{
					gdk_game_manager.log("广告超时", 10f);
				}
				else
				{
					switch (code)
					{
					case 1:
						gdk_game_manager.log("视频广告正在准备");
						break;
					case 2:
						gdk_game_manager.log("用户取消视频");
						cancelCallback();
						break;
					case 3:
						gdk_game_manager.log("广告已经结束");
						callback();
						break;
					case 4:
						gdk_game_manager.log("广告被用户点击");
						break;
					case 5:
						gdk_game_manager.log("广告正在播放中");
						break;
					case 6:
						gdk_game_manager.log("广告遇到其它类型错误失败");
						errCallback();
						break;
					}
				}
			}, extrainfo);*/
		}

		public static void unlockLevelEvent(int level, float score)
		{
			SDKSendEventManager.unlockLevelEvent(level, score);
		}

		public static void sendPlayGameEvent(string time)
		{
			SDKSendEventManager.sendPlayGameEvent(time);
		}

		public static void startGameEvent(int level)
		{
			SDKSendEventManager.startGameEvent(level);
		}

		public static void endGameEvent(int level)
		{
			SDKSendEventManager.endGameEvent(level);
		}

		public static void sendCustomEvent(CustomModel customModel, List<string> value)
		{
			string text = value[0];
			for (int i = 1; i < value.Count; i++)
			{
				string str = "|" + value[i];
				text += str;
			}
			sendCustomEvent(customModel, text);
		}

		public static void sendCustomEvent(CustomModel customModel, string value)
		{
			SDKSendEventManager.sendCustomEvent(customModel.module, customModel.mevent, customModel.step, value);
		}

		public static int getMaxLevelNum()
		{
			return 150;
		}

		public static bool getFuncOpen(string funcName)
		{
			/*JsonObject funcSwitchList = SDKManager.FuncSwitchList;
			if (funcSwitchList.ContainsKey(funcName))
			{
				return funcSwitchList[funcName].ToString() == "1";
			}*/
			return false;
		}

		/*public static bool IsOpenAd()
		{
			if (SDKManager.videoSwitch == 1)
			{
				return true;
			}
			return false;
		}*/

		public static int getNewerLv()
		{
			/*if (SDKManager.AdInfoSwitch.ContainsKey("newerlv"))
			{
				string value = SDKManager.AdInfoSwitch["newerlv"].ToString();
				return Convert.ToInt32(value);
			}*/
			return 8;
		}

		public static int getStartLevel()
		{
			/*if (SDKManager.AdInfoSwitch.ContainsKey("AdStart"))
			{
				string value = SDKManager.AdInfoSwitch["AdStart"].ToString();
				return Convert.ToInt32(value);
			}*/
			return 10;
		}

		public static int getJianGe1()
		{
			/*if (SDKManager.AdInfoSwitch.ContainsKey("jg1"))
			{
				string value = SDKManager.AdInfoSwitch["jg1"].ToString();
				return Convert.ToInt32(value);
			}*/
			return 2;
		}

		public static int getAllStartLevel()
		{
			/*if (SDKManager.AdInfoSwitch.ContainsKey("AdAllStar"))
			{
				string value = SDKManager.AdInfoSwitch["AdAllStar"].ToString();
				return Convert.ToInt32(value);
			}*/
			return 100;
		}

		public static int getJianGe2()
		{
			/*if (SDKManager.AdInfoSwitch.ContainsKey("jg2"))
			{
				string value = SDKManager.AdInfoSwitch["jg2"].ToString();
				return Convert.ToInt32(value);
			}*/
			return 1;
		}

		public static int getJiangeTime()
		{
			/*if (SDKManager.AdInfoSwitch.ContainsKey("timejg"))
			{
				string value = SDKManager.AdInfoSwitch["timejg"].ToString();
				return Convert.ToInt32(value);
			}*/
			return 10;
		}

		public static string getAdType()
		{
			/*if (SDKManager.AdInfoSwitch.ContainsKey("Adgl"))
			{
				string json = SDKManager.AdInfoSwitch["Adgl"].ToString();
				List<int> list = SimpleJson.SimpleJson.DeserializeObject<List<int>>(json);
				int num = gdk_utils.Random(0, 100);
				int count = list.Count;
				if (count >= 3)
				{
					if (num < list[0])
					{
						return "8";
					}
					if (num < list[0] + list[1])
					{
						return "4";
					}
					return "2";
				}
			}
			List<int> list2 = new List<int>();
			list2.Add(50);
			list2.Add(30);
			list2.Add(20);
			int num2 = gdk_utils.Random(0, 100);
			int count2 = list2.Count;
			if (num2 < list2[0])
			{
				return "8";
			}
			if (num2 < list2[0] + list2[1])
			{
				return "4";
			}*/
			return "2";
		}

		public static string getOtherAdType(string adType)
		{
			/*if (SDKManager.AdInfoSwitch.ContainsKey("Adgl"))
			{
				string json = SDKManager.AdInfoSwitch["Adgl"].ToString();
				List<int> list = SimpleJson.SimpleJson.DeserializeObject<List<int>>(json);
				int num = gdk_utils.Random(0, 100);
				int count = list.Count;
				if (count >= 3)
				{
					if (adType == "8")
					{
						if (list[0] == 100)
						{
							return "8";
						}
						num = gdk_utils.Random(0, list[1] + list[2]);
						if (num < list[1])
						{
							return "4";
						}
						return "2";
					}
					if (adType == "4")
					{
						if (list[1] == 100)
						{
							return "4";
						}
						num = gdk_utils.Random(0, list[0] + list[2]);
						if (num < list[0])
						{
							return "8";
						}
						return "2";
					}
					if (adType == "2")
					{
						if (list[2] == 100)
						{
							return "2";
						}
						num = gdk_utils.Random(0, list[1] + list[0]);
						if (num < list[0])
						{
							return "8";
						}
						return "4";
					}
				}
			}*/
			return adType;
		}
	}
}

